import 'package:flutter/animation.dart';
import 'package:get/get.dart';
import 'package:oli/router/MainRoutePath.dart';

class InitLogic extends GetxController with GetSingleTickerProviderStateMixin {
  late AnimationController animationController;
  Rx<Animation<double>?> opacityAnimation = Rx<Animation<double>?>(null);
  Rx<Animation<double>?> scaleAnimation = Rx<Animation<double>?>(null);
  Rx<Animation<Offset>?> icon1SlideAnimation = Rx<Animation<Offset>?>(null);
  Rx<Animation<Offset>?> icon3SlideAnimation = Rx<Animation<Offset>?>(null);
  Rx<Animation<Offset>?> icon2SlideAnimation = Rx<Animation<Offset>?>(null);
  @override
  void onInit() {
    super.onInit();
    animationController = AnimationController(
      vsync: this,
      duration: const Duration(seconds: 3),
    );
    opacityAnimation.value = Tween<double>(begin: 0.0, end: 1.0).animate(
      CurvedAnimation(
        parent: animationController,
        curve: const Interval(0.0, 0.6, curve: Curves.easeInOut),
      ),
    );
    scaleAnimation.value = Tween<double>(begin: 0.5, end: 1.0).animate(
      CurvedAnimation(
        parent: animationController,
        curve: const Interval(0.0, 0.6, curve: Curves.easeInOut),
      ),
    );

    icon1SlideAnimation.value = Tween<Offset>(
      begin: const Offset(-1.0, 0.0),
      end: Offset.zero,
    ).animate(
      CurvedAnimation(
        parent: animationController,
        curve: const Interval(0.2, 0.6, curve: Curves.easeOut),
      ),
    );

    icon2SlideAnimation.value = Tween<Offset>(
      begin: const Offset(0.0, 1.0),
      end: Offset.zero,
    ).animate(
      CurvedAnimation(
        parent: animationController,
        curve: const Interval(0.3, 0.7, curve: Curves.easeOut),
      ),
    );

    icon3SlideAnimation.value = Tween<Offset>(
      begin: const Offset(1.0, 0.0),
      end: Offset.zero,
    ).animate(
      CurvedAnimation(
        parent: animationController,
        curve: const Interval(0.4, 0.8, curve: Curves.easeOut),
      ),
    );
    animationController.forward();
    Future.delayed(const Duration(seconds: 2), () {
      Get.offNamed(MainRoutePath.main);
    });
  }

  @override
  @override
  void onClose() {
    if (animationController.isAnimating) {
      animationController.stop();
    }
    if (!animationController.isDismissed) {
      animationController.dispose();
    }
    super.onClose();
  }
}
